/*
 * Copyright 2025 The JA-SIG Collaborative. All rights reserved.
 * distributed with this file and available online at
 */
package com.lap.auth.adapter.driving.query.login.repository;

import com.lap.auth.adapter.driving.query.login.LoginLogQueryConverter;
import com.lap.auth.adapter.driving.query.login.mapper.LoginLogQueryMapper;
import com.lap.auth.adapter.driving.query.login.po.LoginLogQueryPo;
import com.lap.auth.application.login.dto.LoginLogDto;
import com.lap.auth.application.login.dto.QueryLoginLogPageQuery;
import com.lap.auth.application.login.repository.LoginLogQueryRepository;
import com.lap.framework.common.dto.page.PageResponse;
import java.util.List;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Repository;

@RequiredArgsConstructor
@Repository
public class LoginLogQueryRepositoryImpl implements LoginLogQueryRepository {

  private final LoginLogQueryConverter loginLogQueryConverter;
  private final LoginLogQueryMapper loginLogQueryMapper;

  @Override
  public PageResponse<LoginLogDto> findByConditionPaged(QueryLoginLogPageQuery query) {
    long count = loginLogQueryMapper.countPageByCondition(query);
    if (count == 0L) {
      return PageResponse.ok(count);
    }
    List<LoginLogQueryPo> list = loginLogQueryMapper.selectPageByCondition(query);
    return PageResponse.ok(loginLogQueryConverter.toDtoList(list), count);
  }
}
